
import Head from 'next/head'

<Head>
  <script>
    {
      `(function() {
         var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?e60fb290e204e04c5cb6f79b0ac1e697";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
       })();`
    }
  </script>
</Head>

![LangChain](https://pica.zhimg.com/50/v2-56e8bbb52aa271012541c1fe1ceb11a2_r.gif)





StochasticAI[#](#stochasticai "此标题的永久链接")
=================================

> 
> [随机加速平台](https://docs.stochastic.ai/docs/introduction/)旨在简化深度学习模型的生命周期。

>  从上传和版本控制模型，到训练、压缩和加速，最终投入生产。
> 
> 
> 

本示例介绍如何使用LangChain与`StochasticAI`模型进行交互。

您需要在[这里](https://app.stochastic.ai/workspace/profile/settings?tab=profile)获取API_KEY和API_URL。

```python
from getpass import getpass

STOCHASTICAI_API_KEY = getpass()

```

```python
import os

os.environ["STOCHASTICAI_API_KEY"] = STOCHASTICAI_API_KEY

```

```python
YOUR_API_URL = getpass()

```

```python
from langchain.llms import StochasticAI
from langchain import PromptTemplate, LLMChain

```

```python
template = """Question: {question}

Answer: Let's think step by step."""

prompt = PromptTemplate(template=template, input_variables=["question"])

```

```python
llm = StochasticAI(api_url=YOUR_API_URL)

```

```python
llm_chain = LLMChain(prompt=prompt, llm=llm)

```

```python
question = "What NFL team won the Super Bowl in the year Justin Beiber was born?"

llm_chain.run(question)

```

```python
"  Step 1: In 1999, the St. Louis Rams won the Super Bowl.  Step 2: In 1999, Beiber was born.  Step 3: The Rams were in Los Angeles at the time.  Step 4: So they didn't play in the Super Bowl that year.\n"

```

